function p = predict(Theta1, Theta2, X)
%PREDICT Predict the label of an input given a trained neural network
%   p = PREDICT(Theta1, Theta2, X) outputs the predicted label of X given the
%   trained weights of a neural network (Theta1, Theta2)

% Useful values
m = size(X, 1);
num_labels = size(Theta2, 1);

% You need to return the following variables correctly 
p = zeros(size(X, 1), 1);

% ====================== YOUR CODE HERE ======================
% Instructions: Complete the following code to make predictions using
%               your learned neural network. You should set p to a 
%               vector containing labels between 1 to num_labels.
%
% Hint: The max function might come in useful. In particular, the max
%       function can also return the index of the max element, for more
%       information see 'help max'. If your examples are in rows, then, you
%       can use max(A, [], 2) to obtain the max for each row.
%

% X: 5000 * 400
% param_theta1: 25 * 400
% const_theta1: 25 * 1
param_theta1 = Theta1(:, 2:401);
const_theta1 = Theta1(:, 1);

% param_theta2: 10 * 25
% const_theta2: 10 * 1
param_theta2 = Theta2(:, 2:26);
const_theta2 = Theta2(:, 1);

layer1 = X * param_theta1' + const_theta1';
layer2 = sigmoid(layer1) * param_theta2' + const_theta2';

[maxv, maxi] = max(sigmoid(layer2), [], 2);
p = maxi;

% =========================================================================


end
